/**
 * Created by 赵半山 on 2017/3/17.
 */
$(function(){


    /*-----------------------查看或隐藏密码----------------------------*/
    $('#lookPassword').on('click',function(){
        var $userPassWord=$('#userPassWord');
        var type=$userPassWord.attr('type');
        if(type=='password'){
            $(this).children('i').removeClass('icon-biyan').addClass('icon-yanjing');
            $userPassWord.attr('type','text');

        }else{
            $userPassWord.attr('type','password');
            $(this).children('i').removeClass('icon-yanjing').addClass('icon-biyan');
        }
    });
    /*----------------------手机号码验证-------------------------------*/
    $('#userAccount').blur(function(){
        var reg=/^1[34578]\d{9}$/;
        var value=$(this).val();
       var a= reg.test(value);
       console.log(a);
    });
    /*----------------------用户名和密码登录---------------------------*/
    $('#usernameAndPasswordToLogin').click(function(){
        var userPhone=$('#userAccount').val();
        var password=$('#userPassWord').val();
       if(util.isNull(userPhone)==0 || /^1[34578]\d{9}$/.test()){
           if(util.isNull(password)==0){
               localStorage.setItem("userPhone",userPhone);
               localStorage.setItem("password",password);
               var data={
                   user:userPhone,
                   password:password
               };
                util.ajax('login',data,loginHander);
           }else{
               console.log("密码不能为空");
           }
       }else{
           console.log("电话号码输入有误");
       }
    });
    /*--------------------------登录返回操作---------------------------*/
    function loginHander(data){
        if(data.status==1){
            console.log('登录成功');
        }else{
            console.log('登录失败');
        }
    }
    /*-------------------------注册下一步操作---------------------------*/
    $('#registerNext').on('click',function(){
        var phone=$('#registerPhone').val();
        sessionStorage.setItem('phone',phone);
        var data={
            phone:phone
        };
        util.ajax('sendCode',data,sendCodeHander);
    });
    /*-------------------------注册发送验证码接口---------------------------*/
    function sendCodeHander(data){
        if(data.status==1){

        }
    }
    /*-------------------------注册验证验证码接口---------------------------*/
    $('#registerPasswordSuccess').on('click',function(){
        var phone=sessionStorage.getItem('phone');
        var code=$('#infoCode').val();
        var data={
            phone:phone,
            code:code
        };
        util.ajax('verifyCode',data,verifyCodeHander);
    });
    /*------------------------注册验证码返回值操作---------------------------*/
    function verifyCodeHander(data){
        if(data.status==1){
            var regitsterPassword=$('registerPassword').val();
            var phone =sessionStorage.getItem('phone');
            var datas={
                phone:phone,
                password:regitsterPassword
            };
            util.ajax('savaUserInfo',datas,savaUserInfoHander);
        }else{
            conosle.log('验证码错误，请重新输入');
        }
    }
    /*------------------------注册保存操作返回值操作---------------------------*/
      function savaUserInfoHander(data){
            if(data.status==1){
                console.log('注册成功');
            }else{
                console.log('注册失败')
            }
      }
});